<template>
  <div>
    <table class="table table-bordered">
      <tbody>
        <tr>
          <td><span style="color: red">*</span>姓名</td>
          <td>
            <input type="text" v-model="form.name" />
          </td>
        </tr>
        <tr>
          <td><span style="color: red">*</span>密码</td>
          <td>
            <input type="password" v-model="form.pwd" />
          </td>
        </tr>
        <tr>
          <td></td>
          <td>
            <button class="btn btn-primary" @click="login">登录</button>
          </td>
        </tr>
      </tbody>
    </table>
  </div>
</template>

<script setup lang="ts">
import axios from "axios";
import { onMounted, reactive, ref } from "vue";
import { useRouter } from "vue-router";

const router = useRouter();
const form = reactive({
  id: 0,
  name: "",
  pwd: "",
  fname: "",
  price: "",
  yajin: "",
  renshu: "",
  tupian: "",
  jieshao: "",
});

const login = () => {
  if (!form.name) {
    alert("姓名不能为空");
    return;
  }
  if (!form.pwd) {
    alert("密码不能为空");
    return;
  }
  axios
    .post(
      "https://localhost:7074/api/fangxing/Login?name=" +
        form.name +
        "&pwd=" +
        form.pwd,
      form
    )
    .then((res) => {
      if (res.data > 0) {
        alert("登录失败");
      }
       else {
        alert("登录成功");
        router.push("addxing")
      }
    });
};
</script>

<style scoped></style>
